/*
 * block_cache.h
 *
 *  Created on: Nov 22, 2011
 *      Author: bendischinger
 */

#ifndef BLOCK_CACHE_H_
#define BLOCK_CACHE_H_

#include <pthread.h>
#include <aio.h>

typedef struct blk_cache_ent {
	pthread_mutex_t lock;
	off_t offset;
	struct aiocb aio_arg;
	int *block;
	int in_use;
} blk_cache_ent_t;

typedef struct blk_cache {
	int fd;
	int blk_size;
	int num_entries;
	blk_cache_ent_t *entries;
} blk_cache_t;

void init_block_cache(blk_cache_t *, int fd, int num_entries, int blocksize);
void free_block_cache(blk_cache_t *);
int is_cached_block(blk_cache_t *, off_t offset);
int *get_cached_block(blk_cache_t *, off_t offset);
void return_cached_block(blk_cache_t *, off_t offset);
void invalidate_cached_block(blk_cache_t *cache, off_t offset);
int put_aio_cached_block(blk_cache_t *, off_t offset);
void put_cached_block(blk_cache_t *, off_t offset, int *block);

#endif /* BLOCK_CACHE_H_ */
